<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">
        const collection = {
            "1275": {
                "album": "依然范特西",
                "artist": "周杰伦",
                "tracks": [
                    "听妈妈的话",
                    "千里之外"
                ]
            },
            "2468": {
                "album": "西界",
                "artist": "林俊杰",
                "tracks": [
                    "西界",
                    "杀手"
                ]
            },
            "3245": {
                "artist": "许嵩",
                "tracks": []
            },
            "5439": {
                "album": "遇见"
            }
        }

        // 1.定义方法更新记录:
        // function updateRecords(id,prop,value)
        // 要求：
        // 1).如果传入的value是一个空值，表示将该属性删除
        // 2).传入的prop如果是tracks，则代表添加，其他是修改
        function updateRecords(id, prop, value) {
            if (value != '') {
                if (prop == 'tracks') {
                    collection[id][prop].push(value);
                } else {
                    collection[id][prop] = value
                }
            } else {
                delete collection[id][prop]
            }
        }
        console.log(collection);
// 3245 tracks '有何不可'
// 3245 tracks ''   -->删
// 5439 artist '孙燕姿'
// 5439 album '逆光'
    </script>
</body>

</html>